package com.atguigu.gulimall.order.web;

import com.atguigu.gulimall.order.service.OrderService;
import com.atguigu.gulimall.order.vo.OrderConfirmVo;
import com.atguigu.gulimall.order.vo.OrderSubmitVo;
import com.atguigu.gulimall.order.vo.SubmitOrderResponseVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;

import java.util.concurrent.ExecutionException;

/**
 * @description:
 * @author: BlueSky
 * @create: 2021-09-30 09:11
 **/
@Controller
public class OrderWebController {

	@Autowired
	OrderService orderService;

	@GetMapping("/toTrade")
	public String toTrade(Model model ) throws ExecutionException, InterruptedException {

		 OrderConfirmVo confirmVo = orderService.confirmOrder();

		model.addAttribute("orderConfirmData",confirmVo);

		//展示订单确定的数据
		return "confirm";
	}


	/**
	 * 下单功能
	 */
	@PostMapping("/submitOrder")
	public String submitOrder (OrderSubmitVo vo,Model model){


		 SubmitOrderResponseVo responseVo = orderService.submitOrder(vo);
		//下单失败回到订单确认页重新确认订单信息
		if (responseVo.getCode()==0){
			//下单成功来到支付选择页
			return "pay";
		}else {
			return "redirect:http://ordergulimall.com/toTrade";
		}
	}
}
